//
// Created by Kqj on 25-8-31.
//

#include "show.h"
#include "Tenser.h"

#define TEMP_ADD 10
#define PRESS_ADD 110
#define VOLTAGE_ADD 190

#define MODE_ADD 0
#define POWER_ADD 20
#define MIN_PRESS_ADD 40
#define MAX_PRESS_ADD 60

int8_t show_info_or_info2_flag = 0;

void show_init()
{
    lcd_cs(0);
    lcd_initial();
    lcd_initial();
    lcd_initial();
    TFT_clear();
}

void show_info(OperationMode MODE,int pump_running_flag)
{
    if(show_info_or_info2_flag != 1)
        TFT_clear();
    show_info_or_info2_flag = 1;
//    Fresh_Tenser_data();


    if(MODE == MODE_MANUAL)
    {
        display_char16_16(0,40,RED,手);
        display_char16_16(20,40,RED,动);
        display_char16_16(40,40,RED,模);
        display_char16_16(60,40,RED,式);
    } else if (MODE == MODE_CONSTANT)
    {
        display_char16_16(0,40,RED,恒);
        display_char16_16(10,40,RED,压);
        display_char16_16(40,40,RED,模);
        display_char16_16(60,40,RED,式);
    }

    if(pump_running_flag == 0)
    {
        display_char8_16(0,60,RED,0);
    }
    else if(pump_running_flag == 1)
    {
        display_char8_16(0,60,RED,1);
    }
    display_char16_16(20,220,RED,度);
    display_char8_16(120,220,RED,11);
    display_char8_16(130,220,RED,12);
    display_char8_16(140,220,RED,13);
    display_char8_16(200,220,RED,14);
    display_point(189,232,RED);  //画点，电压值呈10倍传入


//    display_char16_16(40,240,RED,模);
//    display_char16_16(60,240,RED,式);

}


void show_info2()
{
    if(show_info_or_info2_flag != 2)
        TFT_clear();
    show_info_or_info2_flag = 2;

//    Fresh_Tenser_data();
    display_char16_16(0,0,RED,模);
    display_char16_16(20,0,RED,式);


    display_char16_16(0,20,RED,恒);
    display_char16_16(20,20,RED,压);
    display_char16_16(40,20,RED,功);
    display_char16_16(60,20,RED,率);

    display_char16_16(0,40,RED,最);
    display_char16_16(20,40,RED,小);
    display_char16_16(40,40,RED,阈);
    display_char16_16(60,40,RED,值);

    display_char16_16(0,60,RED,最);
    display_char16_16(20,60,RED,大);
    display_char16_16(40,60,RED,阈);
    display_char16_16(60,60,RED,值);

    display_char16_16(20,220,RED,度);
    display_char8_16(120,220,RED,11);
    display_char8_16(130,220,RED,12);
    display_char8_16(140,220,RED,13);
    display_char8_16(200,220,RED,14);
    display_point(189,232,RED);  //画点，电压值呈10倍传入

    display_char8_16(220,20,RED,16);
    display_char8_16(210,40,RED,11);
    display_char8_16(220,40,RED,12);
    display_char8_16(230,40,RED,13);
    display_char8_16(210,60,RED,11);
    display_char8_16(220,60,RED,12);
    display_char8_16(230,60,RED,13);

//    display_char16_16(40,240,RED,模);
//    display_char16_16(60,240,RED,式);

}



void Change_Number_to_cloum(int16_t number,uint8_t  address,uint8_t num)
{
    int8_t  num_char_num = 0;
    for(int i =0; i<num; i++)
    {
        num_char_num = number%10;
        number/=10;
//        if(num_char_num == 0 && number == 0 && i>1)
//            display_char8_16(address-i*10,220,RED,11); //填充空白,无效，运行时不执行该判断
        display_char8_16(address-i*10,220,RED,num_char_num);
    }
}

void Change_Number_to_cloum_right(int16_t number,uint8_t  address,uint8_t num)
{
    int8_t  num_char_num = 0;
    for(int i =0; i<num; i++)
    {
        num_char_num = number%10;
        number/=10;
//        if(num_char_num == 0 && number == 0 && i>1)
//            clean_char8_16(200-i*10,address,RED,num_char_num);
        display_char8_16(200-i*10,address,RED,num_char_num);
    }
}

void Change_Number_to_cloum_right_MODE(OperationMode MODE,uint8_t  address)
{
    if(MODE == MODE_MANUAL)
    {
        display_char16_16(160,address,RED,手);
        display_char16_16(180,address,RED,动);
        display_char16_16(200,address,RED,模);
        display_char16_16(220,address,RED,式);
    } else if (MODE == MODE_CONSTANT)
    {
        display_char16_16(160,address,RED,恒);
        display_char16_16(180,address,RED,压);
        display_char16_16(200,address,RED,模);
        display_char16_16(220,address,RED,式);
    }

}

void Change_Number_to_cloum_right_Power(int16_t number,uint8_t  address,uint8_t num)
{
    int8_t  num_char_num = 0;
    if(number == 100)
        num=3;
    else
        num=2;
    clean_char8_16(190,address,8,16);
    for(int i =0; i<num; i++)
    {
        num_char_num = number%10;
        number/=10;
        display_char8_16(210-i*10,address,RED,num_char_num);
    }
}
void show_down_info(int16_t temp,uint16_t Press,uint16_t Voltage)
{
    Change_Number_to_cloum(temp,TEMP_ADD,2);
    Change_Number_to_cloum(Press,PRESS_ADD,2);
    Change_Number_to_cloum(Voltage,VOLTAGE_ADD,3);

}

void show_right_info(OperationMode MODE,int16_t Power,uint16_t min_press,uint16_t max_press)
{
    Change_Number_to_cloum_right_MODE(MODE,MODE_ADD);
    Change_Number_to_cloum_right_Power(Power,POWER_ADD,3);
    Change_Number_to_cloum_right(min_press,MIN_PRESS_ADD,2);
    Change_Number_to_cloum_right(max_press,MAX_PRESS_ADD,2);

}

void show_square(int location)
{
    clean_char8_80(90,0,RED,1);
    display_line(90,location*20,RED);
}